"use strict";

define('HomeView', [
  'jquery',
  'underscore',
  'backbone',
  'api',
  'text!templates/home.html'
], function ($, _, Backbone, api, tpl) {
  var HomeView;

  HomeView = Backbone.View.extend({
    initialize: function () {
      this.template = _.template(tpl);
    },

    events: {
      "click input[id=addLoc]": "addLoc",
      "click input[id=allLoc]": "allLoc",
      "click input[id=addCate]": "addCate",
      "click input[id=allCate]": "allCate"
    },
    render: function () {
      $(this.el).html(this.template());
      return this;
    },
    addLoc: function () {
      var cityName = $('#cityName').val();
      var zoneName = $('#zoneName').val();
      api.addLoc(cityName, zoneName, function (err, data) {
        if (err) return console.log('err ', err);
        console.log(data);
      });
    },

    allLoc: function () {
      api.allLoc(function (err, data) {
        if (err) return console.log('err ', err);
        console.log(JSON.stringify(data));
      });
    },

    addCate: function () {
      var cateName = $('#cateName').val();
      api.addCate(cateName, function (err, data) {
        if (err) return console.log('err ', err);
        console.log(data);
      });
    },
    allCate: function () {
      api.allCate(function (err, data) {
        if (err) return console.log('err ', err);
        console.log(JSON.stringify(data));
      });
    }

  });
  return HomeView;
});
